package com.example.demo;

import com.example.demo.enity.StudentComponent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.PostConstruct;

@Controller
@ResponseBody //加在类上表示当前类中的所有方法返回的都是非静态页面的数据
public class TextController {


    @Value("${mystr1}")
    private String mystr1;

    @Value("${mystr2}")
    private String mystr2;

    @Value("${mystr3}")
    private String mystr3;

    @Value("${student.name}")
    private String name;

    @Autowired
    private StudentComponent studentComponent;


    @PostConstruct
    public void doPostConstruct() {
        System.out.println("----------------------");
        System.out.println(mystr1);
        System.out.println(mystr2);
        System.out.println(mystr3);
        System.out.println("----------------------");
        System.out.println("name -> " + name);
        System.out.println(studentComponent);
        System.out.println();
    }

    @RequestMapping("/sayHi") // = @WebServlet("/url")
    public String sayHi() {
        return "Hello world -> ";
    }
}
